package com.xushi.service.impl;

import com.xushi.dao.TimePriceMapRepository;
import com.xushi.model.TimePriceMap;
import com.xushi.service.TimePriceMapService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.sql.Timestamp;

/**
 * Created by 14553 on 2018/5/17.
 */
@Service("TimePriceMapService")
@Transactional
public class TimePriceMapServiceImpl implements TimePriceMapService {
    @Autowired
    private TimePriceMapRepository timePriceMapDao;

    public TimePriceMap findByTemplateIdAndTimeId(String templateId, String timeId) {
        return timePriceMapDao.findByTemplateIdAndTimeId(templateId, timeId);
    }

    public TimePriceMap addTimePriceMap(String templateId, String timeId, String price) {
        TimePriceMap timePriceMap = new TimePriceMap();
        Timestamp currTime = new Timestamp(System.currentTimeMillis());
        timePriceMap.setTemplateId(templateId);
        timePriceMap.setTimeId(timeId);
        timePriceMap.setPrice(price);
        timePriceMap.setCreateAt(currTime);
        timePriceMap.setUpdateAt(currTime);
        return timePriceMapDao.save(timePriceMap);
    }
    /*
    //更新时间价格对照表
    public TimePriceMap updateTimePriceMap(String templateName,String time,String price){
        TimePriceMap timePriceMap = timePriceMapDao.findByTemplateNameAndTime(templateName,time);
        Timestamp currTime = new Timestamp(System.currentTimeMillis());
        timePriceMap.setPrice(price);
        timePriceMap.setUpdateAt(currTime);
        return timePriceMapDao.save(timePriceMap);
    }*/
}
